package service

import (
	"singo/model"
	"singo/serializer"
	// "github.com/segmentio/ksuid"
	// "github.com/rs/xid"
)

// UserUpdateService 管理用户更新服务
type UserUpdateService struct {
	ID             string `form:"id" json:"id" binding:"required"`
	Nickname       string `form:"nickname" json:"nickname" binding:""`
	UserName       string `form:"username" json:"username" binding:""`
	UserType       int    `form:"user_type" json:"user_type" binding:""`
	Gender         int    `form:"gender" json:"gender" binding:""`
	OrganizationID string `form:"organization_id" json:"organization_id" binding:""`
	Job            string `form:"job" json:"job" binding:""`
	Rank           int    `form:"rank" json:"rank" binding:""`
	Level          int    `form:"level" json:"level" binding:""`
}

// Update 用户更新
func (service *UserUpdateService) Update() serializer.Response {

	user := model.User{
		UserName:        service.UserName,
		Nickname:        service.Nickname,
		UserType:        service.UserType,
		Gender:          service.Gender,
		OrganizationUID: service.OrganizationID,
		Job:             service.Job,
		Rank:            service.Rank,
		Level:           service.Level,
	}

	// 更新用户
	if err := model.DB.Model(&user).Where("uid = ?", service.ID).Updates(&user).Error; err != nil {
		return serializer.ParamErr("更新失败", err)
	}

	return serializer.BuildUserResponse(user)
}
